<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">


<div th:replace="public/base_update :: html"></div>

<body>
<!-- Start Page Loading -->
<div id="loader-wrapper">
    <div id="loader"></div>
    <div class="loader-section section-left"></div>
    <div class="loader-section section-right"></div>
</div>
<!-- End Page Loading -->


<!-- START MAIN -->
<!-- START WRAPPER -->


<!-- START CONTENT -->
<section id="content">
    <!--Form Advance-->
    <div class="row">
        <div class="col s12 m12 l12">
            <div class="card-panel">
                <h4 class="header2">角色权限添加</h4>
                <div class="row">
                    <form class="col s12" id="send_form" action="">
                        <input type="hidden" id="id" name="id" th:value="${role.id}">
                        <div class="row">
                            <select multiple="multiple"  id="permission" name="permission" class="browser-default">
                            </select>
                        </div>
                        <div class="row">
                            <div class="input-field col s12">
                                <button id="send_btn" class="btn cyan waves-effect waves-light right" type="button"
                                        name="action">提交
                                    <i class="mdi-content-send right"></i>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>


<!-- ================================================
Scripts
================================================ -->

<script th:inline="javascript">
    $(function(){
        initSelect();

    });
    function initSelect() {
        $.ahsjajax( "/unitlinforbase/role/listPermission.crp",
            {roleId:$('#id').val()},
            function(msg) {//msg为返回的数据，在这里做数据绑定
                var row = "";
                for (var i = 0; i < msg.length;i++) {
                    if(msg[i].value !== null){
                        row = "<option value='"+msg[i].value+ "' ";
                        if (msg[i].selected) {
                            row = row + "selected";
                        }
                        row = row + ">"+msg[i].name+"</option>";
                        $("#permission").append(row);
                    }
                }
                $('#permission').multiSelect({});
            });
    }

    $("#send_btn").click(function () {
        var send_form = $('#send_form').serialize();
        console.log(send_form);
        $.ajax({
            type: "post",
            data: send_form,
            url: "/unitlinforbase/role/roleAddPermission.crp",
            dataType: "json",
            success: function (msg) {
                if (msg.success) {
                    Materialize.toast(msg.message, 500,'',function () {
                        dialog.parentclose(true)
                    });
                } else {
                    Materialize.toast(msg.message, 3000);
                }
            },
            error: function ( ) {
                Materialize.toast("网络异常");
            }
        });
    });


</script>

</body>

</html>
